package com;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;

public class SCM_MakeRepository {
	static String[] SRC_DIR = new String[] {
			"C:/develop/WALI/workspace/WALI/java/",
			"C:/develop/WALI/workspace/WALI/WEB/" };
	
	static String DST_DIR = "C:/repository/";
	static String REP_ROOT = null;
	static String SRC_ROOT = null;
	static String SRC_TYPE = null;
	static String ANT_DIR = null;
	static String ANT_BATCH_DIR = null;
	public static void main(String[] args) {
		
		try {

			BufferedReader in = new BufferedReader(new FileReader(DST_DIR+"map.txt"));
			String str = null;

			while ((str = in.readLine()) != null) {
				String[] val = str.split("	");
				
				if(val.length<4){
					REP_ROOT = val[2];
				}else{
					REP_ROOT = val[2]+val[3];
				}				
				
				if(val[1].trim().length()==0){
					val[0] = val[0].replace("/", "");
					SRC_ROOT = "";
				}else{
					SRC_ROOT = "/"+val[1];
				}
				if(val[2].contains("java_")){
					SRC_TYPE = SRC_DIR[0];
				}else{
					SRC_TYPE = SRC_DIR[1];
				}				
				ANT_DIR = "ant/"+val[3].toUpperCase();
				ANT_BATCH_DIR = "ant_batch/"+val[3].toUpperCase();
				System.out.println(new String("rmdir "+DST_DIR+REP_ROOT                                      ).replace("/", "\\")+" /S/Q");
				System.out.println(new String("mkdir "+DST_DIR+REP_ROOT+SRC_ROOT                             ).replace("/", "\\"));
				System.out.println(new String("xcopy "+SRC_TYPE+val[0]+val[1]+" "+DST_DIR+REP_ROOT+SRC_ROOT).replace("/", "\\")+" /EHKQ");
				
				System.out.println(new String("mkdir "+DST_DIR+REP_ROOT+"/"+ANT_DIR                       ).replace("/", "\\"));
				System.out.println(new String("xcopy "+SRC_TYPE+val[0]+ANT_DIR+" "+DST_DIR+REP_ROOT+"/"+ANT_DIR).replace("/", "\\")+" /EHKQ");
				
				System.out.println(new String("mkdir "+DST_DIR+REP_ROOT+"/"+"ant/template"                       ).replace("/", "\\"));
				System.out.println(new String("xcopy "+SRC_TYPE+val[0]+"ant/template"+" "+DST_DIR+REP_ROOT+"/"+"ant/template").replace("/", "\\")+" /EHKQ");
				
				System.out.println(new String("xcopy "+SRC_TYPE+val[0]+"ant/*.properties"+" "+DST_DIR+REP_ROOT+"/"+"ant/").replace("/", "\\")+" /HKQ");
				
				System.out.println(new String("mkdir "+DST_DIR+REP_ROOT+"/"+ANT_BATCH_DIR                      ).replace("/", "\\"));
				System.out.println(new String("xcopy "+SRC_TYPE+val[0]+ANT_BATCH_DIR+" "+DST_DIR+REP_ROOT+"/"+ANT_BATCH_DIR).replace("/", "\\")+" /EHKQ");
				
				System.out.println(new String("mkdir "+DST_DIR+REP_ROOT+"/"+"ant_batch/template"                       ).replace("/", "\\"));
				System.out.println(new String("xcopy "+SRC_TYPE+val[0]+"ant_batch/template"+" "+DST_DIR+REP_ROOT+"/"+"ant_batch/template").replace("/", "\\")+" /EHKQ");
				
				System.out.println(new String("xcopy "+SRC_TYPE+val[0]+"ant_batch/*.properties"+" "+DST_DIR+REP_ROOT+"/"+"ant_batch/").replace("/", "\\")+" /HKQ");
				
				System.out.println(new String("dir "+DST_DIR+REP_ROOT+SRC_ROOT                               ).replace("/", "\\"));
				System.out.println(new String("dir "+DST_DIR+REP_ROOT+"/"+"ant"                                ).replace("/", "\\"));
				System.out.println(new String("dir "+DST_DIR+REP_ROOT+"/"+"ant_batch"                               ).replace("/", "\\"));
				
				//System.out.println(new String("dir "+SRC_TYPE+val[0]+"ant  > c:\\Repository\\o_"+val[0].replace("/", "")+".txt"                                ).replace("/", "\\"));
				//System.out.println(new String("dir "+SRC_TYPE+val[0]+"ant_batch > c:\\Repository\\b_"+val[0].replace("/", "")+".txt"                               ).replace("/", "\\"));
				
				
				System.out.println();
			}
			System.out.println("pause");
			in.close();

		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
}
